package astudy.antlr;

import java.util.List;

import org.antlr.runtime.tree.Tree;

public class ASTParser {
	
	protected void iterate(Tree curNode, String curPath, EventManager em) {

		if (curNode != null) {
			List<ASTListener> listeners = em.getListeners(curPath);
			if (listeners != null) {
				for (ASTListener listener: listeners) {
					listener.process(curNode);
				}
			}
			
		    for (int i = 0; i < curNode.getChildCount(); i ++) {
		    	Tree c = curNode.getChild(i);
		    	String p = curPath +"/" + c.getText();
		    	iterate(c, p, em);
		    }
		}
	}
}
